#include <stdio.h>

#include "gm_sm4.h"

static sm4_func_t *g_ops_fn;
void gm_sm4_register(sm4_func_t *op)
{
	g_ops_fn = op;
}

void gm_sm4_unregister(void)
{
	g_ops_fn = NULL;
}

int32_t gm_sm4_create(uint32_t type)
{
	sm4_func_t *func = NULL;

	if (NULL == g_ops_fn || type >= SM4_MODE_MAX) {
		return -1;
	}
	func = g_ops_fn;

	g_ops_fn = &func[type];

	return 0;
}

int32_t gm_sm4_destroy(void)
{
	return 0;
}

int32_t gm_sm4_enckey(sm4_ctx_t *ctx, uint8_t* key)
{
	g_ops_fn->enckey(ctx, key);

	return 0;
}

int32_t gm_sm4_deckey(sm4_ctx_t *ctx, uint8_t* key)
{
	g_ops_fn->deckey(ctx, key);
	return 0;
}

int32_t gm_sm4_encrypt(sm4_ctx_t *ctx, uint32_t len, uint8_t *input, uint8_t *output)
{
	return g_ops_fn->encdata(ctx, len, input, output);
}

int32_t gm_sm4_decrypt(sm4_ctx_t *ctx, uint32_t len, uint8_t *input, uint8_t *output)
{
	return g_ops_fn->decdata(ctx, len, input, output);
}
